/*
 * Part of the ACID Project
 * Developed in 2011 by Morgan Taschuk
 */
package acid.network;

import acid.plugin.gui.ConfigurationOptions;
import cytoscape.Cytoscape;
import cytoscape.data.CyAttributes;
import edu.asu.emit.qyan.alg.model.Graph;
import edu.asu.emit.qyan.alg.model.Path;
import edu.asu.emit.qyan.alg.model.abstracts.BaseVertex;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author morgan
 */
public class AcidPath extends Path implements Comparable<AcidPath>
{

    protected List<Double> pathWeights;
    private double expressionWeight = 0;
    private List<BaseVertex> vertexList;

    private AcidPath(Graph graph, List<BaseVertex> vertexList, double weight)
    {
        this(vertexList, weight);
        pathWeights = new ArrayList<Double>();
        this.vertexList = vertexList;
        BaseVertex prev = null;
        BaseVertex next = null;

        for (BaseVertex v : this.get_vertices())
        {
            next = v;
            if (prev != null)
            {
                pathWeights.add(graph.get_edge_weight(prev, next));
            }
            prev = next;
        }

    }

    public AcidPath(Graph g, Path p)
    {
        this(g, p.get_vertices(), p.get_weight());
    }

    private AcidPath(List<BaseVertex> _vertex_list, double _weight)
    {
        super(_vertex_list, _weight);
    }

    private AcidPath()
    {
        super();
    }

    public double findPathWeight()
    {
        List<BaseVertex> vs = get_vertices();

        double total = 0;
        total = vs.size();

        double product = 1;

        for (Double v : pathWeights)
        {
            product *= v;
        }

        total += (total / product);
        return total;
    }

    public double getExpressionWeight()
    {
        return expressionWeight;
    }

    public void setExpressionWeight(double expressionWeight)
    {
        this.expressionWeight = expressionWeight;
    }
    

    public List<BaseVertex> getVertexList()
    {
        return vertexList;
    }

    

    @Override
    public int compareTo(AcidPath a)
    {
        Double aW = findPathWeight();
        Double bW = a.findPathWeight();
        return aW.compareTo(bW);
    }

    public String toString()
    {
        String toString = "";
        CyAttributes attributes = Cytoscape.getNodeAttributes();

        for (BaseVertex v : get_vertices())
        {
            toString += attributes.getStringAttribute(new Integer(v.get_id()).toString(),
                    ConfigurationOptions.NAME_ATT) + "   ";
        }

        return toString;
    }
}
